import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_MSG } from 'utils/config';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
import { queryIdpValue } from 'cpaas-front/lib/services/api';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询短信配置列表数据
 * @async
 * @function fetchSMSList
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

export function fetchSMSList(_x) {
  return _fetchSMSList.apply(this, arguments);
}
/**
 * 获取服务类型的值集
 * @async
 * @function fetchTrxStatus
 */

function _fetchSMSList() {
  _fetchSMSList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/sms/servers") : "".concat(CPAAS_MSG, "/v1/sms/servers"), {
              method: 'GET',
              query: _objectSpread({}, param)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchSMSList.apply(this, arguments);
}

export function fetchServerType() {
  return _fetchServerType.apply(this, arguments);
}
/**
 * 添加短信配置信息
 * @async
 * @function createSMS
 * @param {object} params - 请求参数
 * @param {!object} params.tenantId - 租户Id
 * @param {!string} params.serverCode - 账户代码
 * @param {?number} params.serverName - 账户名称
 * @param {!string} params.signName - 短信签名
 * @param {!number} params.serverTypeList - 服务类型
 * @param {!string} params.endPoint - endPoint
 * @param {!string} params.accessKey - accessKey
 * @param {!string} params.accessKeySecret - endPoint
 * @param {!string} params.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _fetchServerType() {
  _fetchServerType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", queryIdpValue('CMSG.SMS_SERVER_TYPE'));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchServerType.apply(this, arguments);
}

export function createSMS(_x2) {
  return _createSMS.apply(this, arguments);
}
/**
 * 编辑短信配置信息
 * @async
 * @function createSMS
 * @param {object} params - 请求参数
 * @param {?number} params.serverName - 账户名称
 * @param {!string} params.signName - 短信签名
 * @param {!number} params.serverTypeList - 服务类型
 * @param {!string} params.endPoint - endPoint
 * @param {!string} params.accessKey - accessKey
 * @param {!string} params.accessKeySecret - endPoint
 * @param {!string} params.enabledFlag - 启用标记
 * @param {!string} params.serverId - serverId
 * @param {!string} params.objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _createSMS() {
  _createSMS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/sms/servers") : "".concat(CPAAS_MSG, "/v1/sms/servers"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createSMS.apply(this, arguments);
}

export function editSMS(_x3) {
  return _editSMS.apply(this, arguments);
}

function _editSMS() {
  _editSMS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/sms/servers") : "".concat(CPAAS_MSG, "/v1/sms/servers"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _editSMS.apply(this, arguments);
}

export function deleteSMS(_x4) {
  return _deleteSMS.apply(this, arguments);
}

function _deleteSMS() {
  _deleteSMS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/sms/servers") : "".concat(CPAAS_MSG, "/v1/sms/servers"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteSMS.apply(this, arguments);
}